import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:animation/components/appbar_base.dart';
import 'package:animation/generated/l10n.dart';
import 'package:animation/tools/update_apk.dart';

class UpdatePage extends StatefulWidget {
  const UpdatePage({super.key});

  @override
  State<UpdatePage> createState() => _UpdatePageState();
}

class _UpdatePageState extends State<UpdatePage> {
  String version = '';

  void getVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    setState(() {
      version = packageInfo.version;
    });
  }

  @override
  void initState() {
    super.initState();
    getVersion();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppbarBase(title: S.of(context).s16),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          spacing: 8,
          children: [
            Material(
                color: Theme.of(context).colorScheme.primaryContainer,
                borderRadius: BorderRadius.circular(8),
                clipBehavior: Clip.antiAlias,
                child: ListTile(
                    title: Text(S.of(context).s18),
                    trailing: Text('v$version'),
                    onTap: () {})),
            Material(
              color: Theme.of(context).colorScheme.primaryContainer,
              borderRadius: BorderRadius.circular(8),
              clipBehavior: Clip.antiAlias,
              child: ListTile(
                  title: Text(S.of(context).s20),
                  subtitle: Text(S.of(context).s21),
                  onTap: () {}),
            ),
            Material(
                color: Theme.of(context).colorScheme.primaryContainer,
                borderRadius: BorderRadius.circular(8),
                clipBehavior: Clip.antiAlias,
                child: ListTile(
                  title: Text(S.of(context).s19),
                  onTap: () {
                    UpdateApk().updateApk(context, displayTips: true);
                  },
                )),
          ],
        ),
      ),
    );
  }
}
